<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 17-11-1
 * Time: 上午10:32
 */

namespace wodrow\models;

use ActiveRecord\Model;
use wodrow\tools\Db;
use wodrow\tools\Tools;

/**
 * This is the model class for table "dyhl_order".
 *
 * @property integer $o_id
 * @property string $o_number
 * @property string $o_vip_name
 * @property string $o_vip_card
 * @property string $o_vip_tel
 * @property integer $o_list_no
 * @property string $o_uname
 * @property integer $o_uid
 * @property integer $o_business_uid
 * @property string $o_branch
 * @property string $o_branch_type
 * @property integer $o_branch_id
 * @property string $o_bank
 * @property integer $o_bank_id
 * @property integer $o_add_time
 * @property integer $o_sell_time
 * @property integer $o_search_time
 * @property integer $o_finishs_time
 * @property integer $o_fuser_time
 * @property integer $o_finishe_time
 * @property string $o_status
 * @property integer $o_before_status
 * @property string $o_quit_status
 * @property string $o_buyer_type
 * @property string $o_buyer
 * @property integer $o_buyer_id
 * @property integer $o_w_id
 * @property string $o_w_group
 * @property string $o_grade
 * @property integer $o_first_time
 * @property integer $o_first_atime
 * @property integer $o_visa_time
 * @property integer $o_org_id
 * @property integer $o_perch
 * @property string $o_perch_name
 * @property integer $o_final_perch
 * @property integer $o_traffic_time
 * @property string $o_vip_num
 * @property string $o_pledge_status
 * @property integer $o_pledge_time
 * @property integer $o_card_date
 * @property string $o_car_plate
 * @property string $o_car_register
 * @property integer $o_pact_gettime
 * @property integer $o_pact_totime
 * @property integer $o_bank_time
 * @property integer $o_quit_time
 * @property string $o_rebate_details
 * @property double $o_rebate_money
 * @property string $o_rebate_status
 * @property integer $o_rebate_date
 * @property integer $o_role_id
 * @property integer $o_visa_status
 * @property integer $o_visa_vtime
 * @property double $o_risk_pay
 * @property string $o_lock_ad
 * @property string $o_lock_bank
 * @property string $o_lock_payments
 * @property double $o_web_risk
 * @property double $o_rebate_per
 * @property string $o_credit_search
 * @property integer $o_pre_mode
 * @property string $o_loan_money
 * @property string $o_trial_status
 * @property string $o_layer_status
 * @property string $o_layer_aucode
 * @property string $o_review_status
 * @property integer $o_suspend_status
 * @property integer $o_oldsys
 * @property string $o_audit_priority
 * @property string $o_deposit
 * @property string $o_deposit_remarks
 * @property integer $o_needpay
 */
class Order extends Model
{
    public static $table_name = "dyhl_order";

    public function attributeLabels()
    {
        return array(
            'o_id' => 'ID',
            'o_number' => '订单号',
            'o_vip_name' => '客户名称',
            'o_vip_card' => '客户身份证',
            'o_vip_tel' => '客户手机号',
            'o_list_no' => '送件序号',
            'o_uname' => '信贷专员',
            'o_uid' => '信贷专员ID',
            'o_business_uid' => '业务来源人',
            'o_branch' => '部门',
            'o_branch_type' => '部门ID dot 网点 dp 部门 rg大区',
            'o_branch_id' => '部门ID',
            'o_bank' => '银行',
            'o_bank_id' => '银行ID',
            'o_add_time' => '提交时间',
            'o_sell_time' => '征信提交时间',
            'o_search_time' => '征信查询时间',
            'o_finishs_time' => '终审提交时间',
            'o_fuser_time' => '审核员审核时间',
            'o_finishe_time' => '终审通过时间',
            'o_status' => '状态',
            'o_before_status' => '预审状态:1无预审,2要预审,3预审通过',
            'o_quit_status' => '退单时状态',
            'o_buyer_type' => '经销商类型',
            'o_buyer' => '经销商',
            'o_buyer_id' => '经销商ID',
            'o_w_id' => '大区ID',
            'o_w_group' => '大区名称',
            'o_grade' => '合作等级',
            'o_first_time' => '初审提交时间',
            'o_first_atime' => '初审审核时间',
            'o_visa_time' => '面签提交时间',
            'o_org_id' => '单位ID',
            'o_perch' => '占位',
            'o_perch_name' => '初审占位人名',
            'o_final_perch' => '层级审核占位',
            'o_traffic_time' => '财务生交时间',
            'o_vip_num' => '客户编号',
            'o_pledge_status' => '注册抵押状态',
            'o_pledge_time' => '注册抵押时间',
            'o_card_date' => 'o_car_register',
            'o_car_plate' => 'o_car_register',
            'o_car_register' => '机动车登记证书号',
            'o_pact_gettime' => '合同收到日期',
            'o_pact_totime' => '送交银行日期',
            'o_bank_time' => '确定银行利率时间',
            'o_quit_time' => '银行退单',
            'o_rebate_details' => '返利详情',
            'o_rebate_money' => '返利金额',
            'o_rebate_status' => '结算状态',
            'o_rebate_date' => '返利生成日期',
            'o_role_id' => '最终审核权限',
            'o_visa_status' => '面签状态:通过:1;提交:2;退单:3;未提交:0',
            'o_visa_vtime' => '面签审核时间',
            'o_risk_pay' => '风险保证金',
            'o_lock_ad' => '垫付 

款操作是否被锁定',
            'o_lock_bank' => '是 

否锁定银行放款操作',
            'o_lock_payments' => '是否锁定财务收支操作',
            'o_web_risk' => '网点承担风险比例',
            'o_rebate_per' => '一年后未出现返点(%)',
            'o_credit_search' => '征信查询数据',
            'o_pre_mode' => '预审模式 1普通 2预审 3超级预审',
            'o_loan_money' => '贷款金额',
            'o_trial_status' => '初审子状态',
            'o_layer_status' => '层审字状态',
            'o_layer_aucode' => '当前层审编码',
            'o_review_status' => '复核状态',
            'o_suspend_status' => '审核暂停状态',
            'o_oldsys' => '是否为老系统订单',
            'o_audit_priority' => '审核优先级',
            'o_deposit' => '需付押金',
            'o_deposit_remarks' => '押金备注',
            'o_needpay' => 'O Needpay',
        );
    }

    /**
     * @param $where
     * @return self
     */
    public static function findOne($where)
    {
//        Tools::log($where);
//        Tools::log(Db::getConditions($where));
//        return Order::first();
        $models = self::find('all', array('conditions' =>Db::getConditions($where)));
        if (count($models)>1){
            throw new \ErrorException('一对一不能有多个');
        }
        /**
         * @var self $model
         */
        $model = $models[0];
        return $model;
    }

    /**
     * @return OrderOldinfo
     */
    public function getOrderOldinfo()
    {
        /**
         * @var $order_oldinfo OrderOldinfo
         */
        $order_oldinfo = OrderOldinfo::findOne(array(array('=', 'o_app_id', $this->o_id)));
        return $order_oldinfo;
    }
}